<template>
  <div class="chart-box">
    <p>{{ stageName }}</p>
    <div class="chart" ref="chart1"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      myChart: null,
    };
  },
  props: {
    data: {
      type: Array,
      default: [],
    },
    stageName: {
      type: String,
      default: "",
    },
 
  },
  methods: {
    getEchartData() {
      this.myChart = this.$echarts.init(this.$refs.chart1);
      let data = this.data;
      const option = {
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: true,
              fontSize: "16",
              fontWeight: "bold",
              position: "center",
              formatter: function (params) {
                // 默认显示第一个数据
                if (params.dataIndex === 1) {
                  return params.value;
                } else {
                  return "";
                }
              },
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "16",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            color: ["#DCDCDC", "#00CD00"],
            data: data,
          },
        ],
      };
      this.myChart.setOption(option);
    },
  },
  mounted() {
    this.getEchartData();
    window.addEventListener("resize", () => {
      this.myChart.resize();
    });
  },
};
</script>
<style lang="scss" scoped>
.chart-box {
  width: 100%;
  height: 100%;
  margin-right: 10px;
  position: relative;
}
.chart {
  padding-top: 10px;
  height: calc(100% - 50px);
}
p {
  text-align: center;
  height: 25px;
  line-height: 25px;
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}
</style>